package njClass.UI{
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class PlusButton extends Sprite {
		private var buttonWidth:int;
		private var buttonHeight:int;
		private var buttonTxt:String;
		private var button_mc:SimpleButton=new SimpleButton();
		private var up_mc:Sprite=new Sprite();
		private var over_mc:Sprite=new Sprite();
		
		public function PlusButton(w:int,h:int,txt:String,txtSize:int=14,txtUpColor:uint=0x000000,txtDownColor:uint=0xFF3300) {
			buttonWidth=w;
			buttonHeight=h;
			buttonTxt=txt;
			up_mc.addChild(doDraw(w,h,true,0xD6E5EC,true,0x666666,15,2));
			over_mc.addChild(doDraw(w,h,true,0xD6E5EC,true,0xFF3300,15,2));
			var text_mc:TextField=new TextField();
			text_mc.selectable=false;
			text_mc.defaultTextFormat=new TextFormat("宋体",txtSize,txtUpColor);
			text_mc.text=buttonTxt;
			text_mc.width=buttonWidth;
			text_mc.height=text_mc.textHeight;
			text_mc.autoSize=TextFieldAutoSize.CENTER;
			text_mc.y=(buttonHeight-text_mc.height)/2;
			up_mc.addChild(text_mc);
			var text_down_mc:TextField=new TextField();
			text_down_mc.selectable=false;
			text_down_mc.defaultTextFormat=new TextFormat("宋体",txtSize,txtDownColor);
			text_down_mc.text=buttonTxt;
			text_down_mc.width=buttonWidth;
			text_down_mc.height=text_down_mc.textHeight;
			text_down_mc.autoSize=TextFieldAutoSize.CENTER;
			text_down_mc.y=(buttonHeight-text_down_mc.height)/2;
			text_down_mc.y=(buttonHeight-text_mc.height)/2;
			over_mc.addChild(text_down_mc);
			button_mc.upState=button_mc.hitTestState=up_mc;
			button_mc.overState=button_mc.downState=over_mc;
			//myMouse.MouseGlowBall(this,2,0x33FF66,2);
			button_mc.addEventListener(MouseEvent.MOUSE_OVER,reportMouseOver);
			button_mc.addEventListener(MouseEvent.MOUSE_UP,reportMouseUp);
			button_mc.addEventListener(MouseEvent.MOUSE_DOWN,reportMouseDown);
			addChild(button_mc);
		}
		
		public function get text():String{
			return buttonTxt;
		}
		
		private function reportMouseDown(e:MouseEvent):void{
			//trace("isDown");
			dispatchEvent(new Event("mouseIsDown"));
		}
		
		private function reportMouseOver(e:MouseEvent):void{
			//trace("isOver");
			dispatchEvent(new Event("mouseIsOver"));
		}
		
		private function reportMouseUp(e:MouseEvent):void{
			//trace("isUp");
			dispatchEvent(new Event("mouseIsUp"));
		}
		
		private function doDraw(w:Number,h:Number,useBg:Boolean=true,bgColor:uint=0x000000,useLine:Boolean=false,lineColor:uint=0x000000,round:int=10,lineSize:int=2):Shape {
			var child:Shape=new Shape;
			if(useBg){
				child.graphics.beginFill(bgColor);
			}
			if(useLine){
				child.graphics.lineStyle(lineSize,lineColor);
			}else{
				lineSize=0;
			}
			child.graphics.drawRoundRect(lineSize,lineSize,w-2*lineSize,h-2*lineSize,round);
			child.graphics.endFill();
			return child;
		}
		
		private function doDrawLine(X0:Number,Y0:Number,X:Number,Y:Number,bgColor:uint=0x000000):void {
			var temp:Shape=new Shape();
			temp.graphics.lineStyle(1,bgColor);
			temp.graphics.moveTo(X0,Y0);
			temp.graphics.lineTo(X,Y);
			//slider.addChild(temp);
		}
	}
}